<?php

/**
 * taller_guardar actions.
 *
 * @package    atenea
 * @subpackage taller_guardar
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class taller_guardarActions extends autotaller_guardarActions
{
  public function executeEdit()
  {  	
    $this->taller_sesion = $this->getTallerSesionOrCreate();

    if ($this->getRequest()->getMethod() == sfRequest::POST)
    {
      $this->updateTallerSesionFromRequest();

      $this->saveTallerSesion($this->taller_sesion);
      
      $this->redirect('invitados/edit');
/*      $this->setFlash('notice', 'Your modifications have been saved');

//      if ($this->getRequestParameter('save_and_add'))
      {
        return $this->redirect('taller_guardar/create');
      }
      else if ($this->getRequestParameter('save_and_list'))
      {
        return $this->redirect('taller_guardar/list');
      }
      else
      {
        return $this->redirect('taller_guardar/edit?id='.$this->taller_sesion->getId());
      }*/
    }
    else
    {
      $this->labels = $this->getLabels();
    }
  
}
	  
	public function executeSave()
  {
    return $this->forward('taller_guardar', 'edit');
  }
   
protected function updateTallerSesionFromRequest()
  {
    $taller_sesion = $this->getRequestParameter('taller_sesion');

    if (isset($taller_sesion['taller_id']))
    {
    $this->taller_sesion->setTallerId($taller_sesion['taller_id'] ? $taller_sesion['taller_id'] : null);
    }
    if (isset($taller_sesion['unidad_id']))
    {
    $this->taller_sesion->setUnidadId($taller_sesion['unidad_id'] ? $taller_sesion['unidad_id'] : null);
    }
    if (isset($taller_sesion['num_horas']))
    {
      $this->taller_sesion->setNumHoras($taller_sesion['num_horas']);
    }
    if (isset($taller_sesion['observaciones']))
    {
      $this->taller_sesion->setObservaciones($taller_sesion['observaciones']);
    }
    if (isset($taller_sesion['lugar']))
    {
      $this->taller_sesion->setLugar($taller_sesion['lugar']);
    }
    if (isset($taller_sesion['cupos']))
    {
      $this->taller_sesion->setCupos($taller_sesion['cupos']);
    }
    if (isset($taller_sesion['fecha_inicio']))
    {
      if ($taller_sesion['fecha_inicio'])
      {
        try
        {
          $dateFormat = new sfDateFormat($this->getUser()->getCulture());
                              if (!is_array($taller_sesion['fecha_inicio']))
          {
            $value = $dateFormat->format($taller_sesion['fecha_inicio'], 'i', $dateFormat->getInputPattern('d'));
          }
          else
          {
            $value_array = $taller_sesion['fecha_inicio'];
            $value = $value_array['year'].'-'.$value_array['month'].'-'.$value_array['day'].(isset($value_array['hour']) ? ' '.$value_array['hour'].':'.$value_array['minute'].(isset($value_array['second']) ? ':'.$value_array['second'] : '') : '');
          }
          $this->taller_sesion->setFechaInicio($value);
        }
        catch (sfException $e)
        {
          // not a date
        }
      }
      else
      {
        $this->taller_sesion->setFechaInicio(null);
      }
    }
    if (isset($taller_sesion['fecha_final']))
    {
      if ($taller_sesion['fecha_final'])
      {
        try
        {
          $dateFormat = new sfDateFormat($this->getUser()->getCulture());
                              if (!is_array($taller_sesion['fecha_final']))
          {
            $value = $dateFormat->format($taller_sesion['fecha_final'], 'i', $dateFormat->getInputPattern('d'));
          }
          else
          {
            $value_array = $taller_sesion['fecha_final'];
            $value = $value_array['year'].'-'.$value_array['month'].'-'.$value_array['day'].(isset($value_array['hour']) ? ' '.$value_array['hour'].':'.$value_array['minute'].(isset($value_array['second']) ? ':'.$value_array['second'] : '') : '');
          }
          $this->taller_sesion->setFechaFinal($value);
        }
        catch (sfException $e)
        {
          // not a date
        }
      }
      else
      {
        $this->taller_sesion->setFechaFinal(null);
      }
    }
    if (isset($taller_sesion['hora_inicio']))
    {
      $this->taller_sesion->setHoraInicio($taller_sesion['hora_inicio']);
    }
  }
  
  
  protected function saveTallerSesion($taller_sesion)
  {
   // $taller_sesion->save();
     //$ateneausuario->save();
      $user = $this->getUser();
      //$ids   = $this->ateneausuario->getId();
  	  $user->setAttribute('taller', $taller_sesion);      
      
  }
  
}
